package com.springboot.aspect;

import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.springboot.util.AopLogger;

@Aspect
@Component
public class LoggerAspect
{
    private final static Logger logger = LoggerFactory.getLogger(LoggerAspect.class);

    @Pointcut("execution(public * com.springboot.controller..*.*(..))")
    public void log()
    {
    }

    @Around("log()")
    public void doBefore(ProceedingJoinPoint joinpoint) throws Throwable
    {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attributes.getRequest();
        logger.info("url={}", request.getRequestURI());
        logger.info(" request method={}", request.getMethod());
        logger.info("romote url={}", request.getRequestURI());
        logger.info("class method={}",
                joinpoint.getSignature().getDeclaringTypeName() + "." + joinpoint.getSignature().getName());
        logger.info("param = {}",joinpoint.getArgs());
        AopLogger.around(joinpoint);

    }

}
